import time

from selenium import webdriver

from ..common.ui.Selector import Selector
from .Button import Button
from .Multiselect import MulitSelect
import pytest


def test_no_datasource_set():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/multiselect/index.html")
    time.sleep(2);
    try:
        mulitSelect = MulitSelect(browser, 'multiselect', Selector.ID)
        mulitSelect.setValue('one','two','five')
        assert ['one','two','five'] == mulitSelect.getValue()
    finally:
        browser.close();

def test_with_datasource_set():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/multiselect/index.html")
    time.sleep(2)
    try:
        Button(browser, 'btn7', Selector.ID).click()
        mulitSelect = MulitSelect(browser, 'multiselect', Selector.ID)
        mulitSelect.setValue('第1本书')
        time.sleep(2)
        assert ['第1本书'] == mulitSelect.getValue()
    finally:
        browser.close()

def test_no_existvalue_set():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/multiselect/index.html")
    time.sleep(2)
    try:
        mulitSelect = MulitSelect(browser, 'multiselect', Selector.ID)
        mulitSelect.setValue('xxx')
        assert [] == mulitSelect.getValue()
    finally:
        browser.close();

if __name__ == '__main__':
    pytest.main(['-s','MultiSelect_test.py']);
